/*
 *  Copyright 2002 by Texas Instruments Incorporated.
 *  All rights reserved. Property of Texas Instruments Incorporated.
 *  Restricted rights to use, duplicate or disclose this code are
 *  granted through contract.
 *  
 */
/*
 *  ======== appThreads.c ========
 *
 *  Initialization of all threads, definition of global variables
 *  and buffers
 */
#include <std.h>

/* CSL */
#include <csl.h>
#include <csl_dat.h>

/* RF5 library modules */
#include <chan.h>
#include <icc.h>
#include <scom.h>
#include <utl.h>

#include "appResources.h"   /* application-wide common info */
#include "appThreads.h"     /* thread-wide common info */

/* invididual threads */
#include "process/thrProcess.h"
#include "capture/thrCapture.h"
#include "display/thrDisplay.h"
#include "control/thrControl.h"

/*
 *  ======== appThreadInit ========
 *
 *  Initialize application threads.
 */
Void appThreadInit() 
{
/*
     * Open DAT module to perform DMA transfers.
     * Use low priority transfer requests for all data transfers
     *     submitted by DAT.  2D transfers are allowed.  
     */
    DAT_open(DAT_CHAANY, DAT_PRI_LOW, DAT_OPEN_2D);
    
    // initialize RF5 modules
    CHAN_init();
    ICC_init();
    SCOM_init();

    // set up RF5 modules
    CHAN_setup( EXTERNALHEAP, EXTERNALHEAP, EXTERNALHEAP, 
                SCRBUCKETS, NULL, NULL );
                
	// name LOG objects to be used for error/warning/general/debug messages
	UTL_setLogs( &logTrace, &logTrace, &logTrace, &logTrace );

    // initialize tasks
    thrDisplayInit();
    thrDisplayStartup();
    UTL_logDebug( "Video display started" );

    thrCaptureInit();
    thrCaptureStartup();
    UTL_logDebug( "Video capture started" );

    thrProcessInit();
    thrProcessStartup();
    UTL_logDebug( "Process thread started" );

    thrControlInit();
    thrControlStartup();
    UTL_logDebug( "Control thread started" );
    
    // show heap usage, now that all threads are initialized
    UTL_showHeapUsage( INTERNALHEAP );
    UTL_showHeapUsage( EXTERNALHEAP );
}

